package com.cos.lession72.slice;

import com.cos.lession72.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.Text;

public class TextAbilitySlice extends AbilitySlice {
    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        setUIContent(ResourceTable.Layout_ability_text);
        Text t = (Text) findComponentById(ResourceTable.Id_text1);
        // 跑马灯效果  文字滚动效果
        t.setTruncationMode(Text.TruncationMode.AUTO_SCROLLING);
        // 始终处于自动滚动状态
        t.setAutoScrollingCount(Text.AUTO_SCROLLING_FOREVER);
        // 启动跑马灯效果
        t.startAutoScrolling();
        t.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                //设置文本  覆盖原有的内容
                //t.setText("wa");
                //在原有的内容上进行追加文本
                //t.append("a");
                //文本的内容
                String text = t.getText();
                if (text.equals("hello")) {
                    t.setText("world");
                }else{
                    t.setText("hello");
                }
            }
        });
    }
}
